<template>
  <div id="app">
    <keep-alive>
      <router-view />
    </keep-alive>
  </div>
</template>
<script>
import { getTypeAndAddress, initWalletInfo } from "@/common/connectWallet";

import { mapGetters } from "vuex";
export default {
  name: "App",
  computed: {
    ...mapGetters(["getUserInfo"]),
  },
  data() {
    return {
      timeIndex: 1,
    };
  },
  async created() {
    const ret = await initWalletInfo();
    console.log('ccccc',ret)
    // const ret = await getTypeAndAddress();
    if (ret != false) {
      this.$store.commit("setUserInfo", ret);
      window.location.reload();
    }
  },
  mounted() {
    try {
      document.addEventListener("visibilitychange", this.handleVisiable);
    } catch (error) {
      //
    }
  },
  destroyed() {
    try {
      document.removeEventListener("visibilitychange", this.handleVisiable);
    } catch (error) {
      //
    }
  },
  methods: {
    handleVisiable(e) {
      let now;
      let times;
      switch (e.target.visibilityState) {
        case "prerender":
          console.log("网页预渲染，内容不可见");
          break;
        case "hidden":
          this.timeIndex = new Date().getTime();
          console.log("内容不可见，处理后台、最小化、锁屏状态");
          break;
        case "visible":
          console.log("处于正常打开");
          now = new Date().getTime();
          times = now - this.timeIndex;
          if (+times >= 1000 * 60) {
            window.location.reload();
          }
          break;
      }
    },
  },
};
</script>
<style scoped>
#app {
  font-size: 12px;
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #ffffff;
  background: #090A1B;
  min-height: 100vh;
  font-family: PingFangSC-regular;
}
</style>
